import Vue from 'vue'
import dialog from './dialog.vue'
let dialogConstructor = Vue.extend(dialog)

let dialogInstance = function (options) {
    let dialogOptions = {
        title: "",
        confirm: '',
        cancel: '',
        type: '',
        message: '',
        close: true,
        update: false,
    }
    return new Promise((res, rej) => {
        let dialogEl = new dialogConstructor({
            el: document.createElement('div')
        })
        dialogEl.options = Object.assign(dialogOptions, options)
        dialogEl.confirm = function () {
            res(true)
            dialogEl.control = false
        }
        dialogEl.cancel = function () {
            rej(false)
            dialogEl.control = false
        }
        document.body.appendChild(dialogEl.$el)
    })
}
export default dialogInstance
